<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>心跳动画效果</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background-color: #f0f0f0;
        }

        .container {
            text-align: center;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            max-width: 500px;
            width: 100%;
        }

        .demo-box {
            width: 150px;
            height: 150px;
            margin: 20px auto;
            background-color: #F44336;
            color: white;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 20px;
            border-radius: 50%;
        }

        .controls {
            margin-top: 20px;
        }

        button {
            padding: 10px 20px;
            margin: 0 10px;
            border: none;
            border-radius: 4px;
            background-color: #2196F3;
            color: white;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s;
        }

        button:hover {
            background-color: #0b7dda;
        }

        .heartbeat {
            animation: heartbeat 1.5s ease-in-out infinite;
        }

        @keyframes heartbeat {
            0% { transform: scale(1); }
            14% { transform: scale(1.3); }
            28% { transform: scale(1); }
            42% { transform: scale(1.3); }
            70% { transform: scale(1); }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>心跳动画效果</h1>
        <div class="demo-box" id="demoBox">💖</div>
        <div class="controls">
            <button onclick="startHeartbeat()">开始心跳</button>
            <button onclick="stopHeartbeat()">停止心跳</button>
        </div>
        <div class="code-section">
            <h3>CSS代码:</h3>
            <pre><code>.heartbeat {
  animation: heartbeat 1.5s ease-in-out infinite;
}

@keyframes heartbeat {
  0% { transform: scale(1); }
  14% { transform: scale(1.3); }
  28% { transform: scale(1); }
  42% { transform: scale(1.3); }
  70% { transform: scale(1); }
}</code></pre>
        </div>
    </div>

    <script>
        const box = document.getElementById('demoBox');

        function startHeartbeat() {
            box.classList.add('heartbeat');
        }

        function stopHeartbeat() {
            box.classList.remove('heartbeat');
        }
    </script>
</body>
</html>